<?php
class Zend_View_Helper_LoggedInAs extends Zend_View_Helper_Abstract
{
	public function loggedInAs ()
	{

		$auth = Zend_Auth::getInstance();
		if ($auth->hasIdentity()) {

			$dbAdapter = Zend_Db_Table::getDefaultAdapter();
			$email = $auth->getIdentity()->email;
			$role = $auth->getIdentity()->designation;
			$logoutUrl = $this->view->url(array('module'=>'default','controller'=>'index','action'=>'logout'), null, true);
			return 'Witaj ' .$role.' '. $email .  '. <a href="'.$logoutUrl.'">Wyloguj</a>';
		}

		$request = Zend_Controller_Front::getInstance()->getRequest();
		$module = $request->getModuleName();
		$controller = $request->getControllerName();
		$action = $request->getActionName();
		if($module == 'default' && $controller == 'index' && $action == 'index') {
			return '';
		}
		$loginUrl = $this->view->url(array('module'=>'default','controller'=>'index', 'action'=>'index'));
		return '<a href="'.$loginUrl.'">Zaloguj</a>';

	}

}

